package com.kx.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @RequestMapping放到类上
 */
@Controller
@RequestMapping("/user")
public class MyController {

    /**
     * @RequstMapping：请求映射
     *      属性：method,表请求方式get、post、put、delete等
     * @return
     */
    @RequestMapping(value = "/some.do",method = RequestMethod.GET)
    public ModelAndView doSome() {  //doGet --service请求处理
        ModelAndView mv = new ModelAndView();
        mv.addObject("msg", "欢迎使用");
        mv.addObject("fun", "执行的是doSome方法");
        mv.setViewName("show");
        mv.setViewName("other");
        return mv;
    }

    @RequestMapping(value = "/other.do",method = RequestMethod.POST)
    public ModelAndView doOther() {
        ModelAndView mv = new ModelAndView();
        mv.addObject("msg", "欢迎使用");
        mv.addObject("fun", "执行的是Other方法");
        mv.setViewName("other");
        return mv;
    }
    @RequestMapping(value = "/first.do")
    public ModelAndView doFirst(HttpServletRequest request, HttpServletResponse response, HttpSession session) {
        ModelAndView mv = new ModelAndView();
        mv.addObject("msg", "欢迎使用"+request.getParameter("name"));
        mv.addObject("fun", "执行的是Other方法");
        mv.setViewName("other");
        return mv;
    }
}
